package com.easy.util;
import cn.hutool.crypto.digest.DigestUtil;

public class PasswordDecode {
    private static int[] char_arr={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
    public static String encryption(String pass){
        //加密次数
        int index_count=(int)(Math.random()*char_arr.length);
        //加密盐值
        int index_salt=(int)(Math.random()*char_arr.length);
        String result=pass;
        for(int i=0;i<char_arr[index_count];i++){
            result=result+(char)char_arr[index_salt];
            result= DigestUtil.md5Hex(result);
        }
        result=(char)char_arr[index_count]+result+(char)char_arr[index_salt];
        return result;
    }

    public static void main(String[] args) {
        System.out.println(encryption("123123"));
    }
    
    public static boolean verify(String pass,String decode){
        //加密次数
        char char_count=decode.charAt(0);
        //加密盐值
        char char_salt=decode.charAt(decode.length()-1);

        for(int i=0;i<char_count;i++){
            pass=pass+char_salt;
            pass=DigestUtil.md5Hex(pass);
        }
        return decode.equals(char_count+pass+char_salt);
    }

}